const baseURL = 'https://lottery.qnsyw.cn/api/';
export const myRequesy = (options) => {
  return new Promise((resolve, reject) => {
    wx.request({
      url: baseURL + options.url,
      method: options.method || 'GET',
      data: options.data || {},
      header: {
        Authorization: wx.getStorageSync('userInfo').token
      },
      success: (res) => {
        if (res.data.code === 2001 || res.data.code === 2002 || res.data.code === 2003) {
          wx.removeStorage({
            key: 'userInfo',
            success() {
              wx.switchTab({
                url: '/pages/user/user',
              })
            }
          })
        }
        resolve(res)
      },
      fail: (err) => {
        reject(err)
      }
    })
  })
}

// let token= wx.getStorageSync('userInfo').token
// let header = {'content-type': 'application/json'};
// if (token) {
//   header['Authorization'] = wx.getStorageSync('userInfo').token
// }
export const homeRequesy = (options) => {
  return new Promise((resolve, reject) => {
    wx.request({
      url: baseURL + options.url,
      method: options.method || 'GET',
      data: options.data || {},
      header: options.header || {},
      success: (res) => {
        resolve(res)
      },
      fail: (err) => {
        reject(err)
      }
    })
  })
}